﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ZX.CRM.Report.CrmReport;
using ZX.CRM.Bussiness;
namespace ZX.WebApp.Crm.Report
{
    /// <summary>
    /// 客户分析界面
    /// </summary>
    public partial class RptCustomerAnalysis : System.Web.UI.Page
    {
        BCrmReport BReport = new BCrmReport();   //数据业务类
        protected void Page_Load(object sender, EventArgs e)
        {
            string StartDate = Request.QueryString["StartDate"] == null ? "" : Request.QueryString["StartDate"];
            string EndDate = Request.QueryString["EndDate"] == null ? "" : Request.QueryString["EndDate"];
            string type = Request.QueryString["type"] == null ? "" : Request.QueryString["type"];
            string sDept = Request.QueryString["id"] == null ? "" : Request.QueryString["id"];
            if (sDept.Trim().Length == 0) //
            {
                return;
            }
            else

                DoReport(sDept, DateTime.Parse(StartDate), DateTime.Parse(EndDate), type);
        }
        /// <summary>
        /// 生成报表
        /// </summary>
        /// <param name="Idept">部门ID</param>
        /// <param name="startdate">开始时间</param>
        /// <param name="enddate">结束时间</param>
        /// <param name="type">0:营销中心1:分公司2:团队3:个人</param>
        private void DoReport(string Idept, DateTime startdate, DateTime enddate, string type)
        {
            if (Idept == "" || type == "") return;

            DataSet myDataSet = new DataSet();
            myDataSet.DataSetName = "DsCustomerAnalysis";
            DataTable TbChannel = new DataTable();
            DataTable TbTrade = new DataTable();
            DataTable TbProduct = new DataTable();
            DataTable TbPerson = new DataTable();
            DataTable TbCity = new DataTable();

            //全公司回款渠道
            TbChannel = BReport.ReturnTableChannelName(new Guid(Idept), startdate, enddate, type);
            //全公司回款行业 
            TbTrade = BReport.ReturnTableTradeName(new Guid(Idept), startdate, enddate, type);
            //全公司回款规模
            TbPerson = BReport.ReturnTablePersonName(new Guid(Idept), startdate, enddate, type);
            //全公司回款产值
            TbProduct = BReport.ReturnTableProductName(new Guid(Idept), startdate, enddate, type);
            //回款城市
            TbCity = BReport.ReturnTableCityName(new Guid(Idept), startdate, enddate, type);

            TbChannel.TableName = "TbChannel";
            TbTrade.TableName = "TbTrade";
            TbProduct.TableName = "TbProduct";
            TbPerson.TableName = "TbPerson";
            TbCity.TableName = "TbCity";
            myDataSet.Tables.Add(TbChannel.Copy());
            myDataSet.Tables.Add(TbTrade.Copy());
            myDataSet.Tables.Add(TbProduct.Copy());
            myDataSet.Tables.Add(TbPerson.Copy());
            myDataSet.Tables.Add(TbCity.Copy());
            ZX.CRM.Report.CrmReport.RptCustomerAnalysis crm = new ZX.CRM.Report.CrmReport.RptCustomerAnalysis();
            crm.DataSource = myDataSet;
            Rv.Report = crm;
        }

    }

}
